﻿using System.Drawing;
using System.Drawing.Drawing2D;
using FBEntities.FBObjects;
using FBEntities.FBObjects.User;
using XFControls.Utils;
using XDAFacebook;

#pragma warning disable 1591
namespace XFControls.XFPanels.XFPanelItems
{
    public class XFItemFriend : XFItemBase
    {
        private string _name;
        private int height = Settings.IconSize;
        private Rectangle _iconRec;

        public XFItemFriend()
        {
            Style = new XFItemStyle
                        {
                            BackgroundColor = Color.White,
                            DashStyleBottom = DashStyle.Dash,
                            TextFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold),
                            SecondaryTextFont = new Font(FontFamily.GenericSansSerif, 6, FontStyle.Regular),
                            SelectedBackgroundColor = Color.Black,
                            SelectedTextColor = Color.White,
                            SelectedSecondaryTextColor = Color.AliceBlue,
                            TextColor = Color.Black,
                            SecondaryTextColor = Color.DimGray,
                            Padding = 5
                        };
            height += Style.PaddingTop + Style.PaddingBottom;
            ItemType = XFItemType.Clickable;

            _iconRec = new Rectangle(Style.PaddingLeft, Style.PaddingTop, Settings.IconSize, Settings.IconSize);
        }

        public string Name { get; set; }
        public string status { get; set; }
        public FBProxyPerson Friend { get; set; }

        public override int GetHeight()
        {
            if (Visible)
                return height;
            return 0;
        }

        public override void ItemPaint(Graphics g, int x, int y)
        {
            base.ItemPaint(g, x, y);
            int width = GetWidth();

            Font fontMain = getCurrentFont(false);
            Font fontSecondary = getCurrentFont(true);
            Color colorMain = getCurrentFontColor(false);
            Color colorSecondary = getCurrentFontColor(true);

            DrawIcon(Friend.Picture.url, g, _iconRec);
            //DrawUI("iconThumb", g, _iconRec);

            if (string.IsNullOrEmpty(_name))
                _name = XFControlUtils.EllipsisWord(width, Name, fontMain);

            using (var b = new SolidBrush(colorMain))
                g.DrawString(_name, fontMain, b, x + height, y + Style.PaddingTop);

            if (string.IsNullOrEmpty(status)) return;
            using (var b = new SolidBrush(colorSecondary))
                g.DrawString(status, fontSecondary, b, x + height, y + height >> 1);
        }

        public override XFItemClickResult GetClickResult()
        {
            if (Parent == null)
                return XFItemClickResult.Nothing;

            FBPerson friendProf = Friend.ToPerson();
            //friendProf.Parse();

            XFPanelList rp = XFItemControlUtils.SetupProfile(friendProf);

            var back = new XFItemBackHeader();

            rp.AddHeaderItem(back);
            Parent.SetRightPanel(rp);

            if (Parent.Parent != null && Parent.Parent is XFPanelContainer)
                ((XFPanelContainer)Parent.Parent).SetHeaderLeftButton(new XFButtonBack());

            rp.ShowAlphaBar(false);
            rp.ShowScrollbar(true);

            return XFItemClickResult.SlideLeft;
        }
    }
}
#pragma warning restore 1591
